package work.fram;

import work.config.Constant;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class WriterMaker {


    public static MyWriter create(String name) {

        File file = new File(Constant.work, name + ".txt");

        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                return null;
            }
        }

        try {
            return new MyWriter(new FileWriter(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static class MyWriter {

        Writer writer;

        public MyWriter(Writer writer) {
            this.writer = writer;
        }

        public void writeLine(String line) {
            try {
                writer.write(line + "\n");
                writer.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void close() {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }


}
